home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Y2K was a hack written for MacHack 1988 by Simon Fraser and John McMullen,
- ** extending the original idea for Y2K from Jon Kalb.
- **
- ** Y2K was implemented by starting with the Apple DTS sample code
- ** The original copyright blurb appears below.
- */
-
- /*
- **
- ** Apple Macintosh Developer Technical Support
- **
- ** Sample code demonstrating how to patch PowerOff key
- **
- ** by Brian Bechtel, Apple Developer Technical Support
- **
- ** File: PatchPowerOff.c
- **
- ** Copyright © 1995 Apple Computer, Inc.
- ** All rights reserved.
- **
- ** You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DTS Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes.
- */
- #include <Gestalt.h>
- #include <Resources.h>
- #include <DeskBus.h>
- #include <Errors.h>
- #include <OSUtils.h>
- #include <Traps.h>
- #include <SetupA4.h>
- #include <A4Stuff.h>
-
- #include "ShowInitIcon.h"
- #include "InstallCursorHack.h"
- #include "PrefResource.h"
- #include "rotato.h"
-
- #define kRotatoIconID 128 /* matches the resID in the 68K Project preferences */
- #define kRotatoBadInstallIconID 129
-
- #define USE_DEBUGGER_CALLS
-
- void main(void);
-
- #define kPi 3.1415926535898
-
- /* main */
-
- void main(void)
- {
- long oldA4;
- TPrefsData prefsData = {0};
- Boolean installedOK;
- TPrefsDataPtr globalDataPtr = nil;
- OSErr err;
-
- /// set up our A4 context for _this file_
- oldA4 = SetCurrentA4();
- RememberA4();
-
- err = PrepareServiceFragment(&prefsData);
- if (err != noErr)
- {
- //Str255 errNum;
- //NumToString(err, errNum);
- //DebugStr(errNum);
- return;
- }
-
- // allocate a sys ptr for our global data
- globalDataPtr = (TPrefsDataPtr)NewPtrSys(sizeof(TPrefsData));
- if (!globalDataPtr)
- {
- //DebugStr("\pFailed to allocate sys ptr");
- return;
- }
-
- // copy the data over
- *globalDataPtr = prefsData;
-
- // install a gestalt value to get to the global data
- err = NewGestaltValue(kDataGestaltSelector, (long)globalDataPtr);
- if (err != noErr)
- {
- //DebugStr("\pFailed to create Gestalt selector");
- return;
- }
-
- // now we have to call main to set up global data in the fragment
- // we could also do this by exporting the global data from the fragment, I guess
- err = (*globalDataPtr->setupProc)();
- if (err != noErr)
- {
- //DebugStr("\pFailed to call SetupData");
- return;
- }
-
- // look ma, no patches!
- installedOK = InstallCursorHack(globalDataPtr);
- ShowInitIcon(installedOK ? kRotatoIconID : kRotatoBadInstallIconID, true);
-
- // restore the a4 world
- SetA4(oldA4);
-
- //DebugStr("\pDone INIT code");
- }
-